﻿using System.Collections;
using System.Collections.Generic;

namespace ZhhbSoft.Data.Criterion
{
    /// <summary>
    ///NodeCollection 的摘要说明
    /// </summary>
    public class NodeCollection : INodeCollection
    {
        protected IList<Node> _nodes = new List<Node>();
        protected Node _Expression;
        public IList<Node> Nodes
        {
            get
            {
                return _nodes;
            }
            set { _nodes = value; }
        }
        public Node this[int index]
        {
            get
            {
                return _nodes[index];
            }
        }

        public Node Expression
        {
            get { return _Expression; }
            set { _Expression = value; }
        }

        #region ICollection<Node> 成员

        public void Add(Node node)
        {
            _nodes.Add(node);
            if (_Expression != null && _Expression.Childs != this)
            {
                _Expression.Childs.Add(node);
            }
        }

        public void Clear()
        {
            _nodes.Clear();
        }

        public bool Contains(Node item)
        {
            return _nodes.Contains(item);
        }

        public void CopyTo(Node[] array, int arrayIndex)
        {
            _nodes.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return _nodes.Count; }
        }

        public bool IsReadOnly
        {
            get { return _nodes.IsReadOnly; }
        }

        public bool Remove(Node item)
        {
            return _nodes.Remove(item);
        }

        #endregion

        #region IEnumerable<Node> 成员

        public IEnumerator<Node> GetEnumerator()
        {
            return _nodes.GetEnumerator();
        }

        #endregion

        #region IEnumerable 成员

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _nodes.GetEnumerator();
        }

        #endregion
    }
}